﻿using System;
using System.Collections.Generic;
using YmtAuth.Domain.Model.Safe;
using YmtAuth.Domain.Repository.MySql;

namespace YmtAuth.Domain.Repository
{
    public interface IIpAreaInfoRepository : IMySQLRepository<IpAreaInfoAuthEntity>
    {
        IpAreaInfoAuthEntity.IpAreaInfo FindIpAreaInfo(long ipStart);
        bool IpAreaInfoExists(long ipStart);
        IEnumerable<IpAreaInfoAuthEntity> FindUserFirstAuthAreaInfo(int userid, int authStatus);
        IpAreaInfoAuthEntity FindAreaInfoAuthEntity(int userid, string country, string province, string city);
        IpAreaInfoAuthEntity FindAreaInfoAuthEntity(int userid, string country, string province, int status);
        IpAreaInfoAuthEntity FindAreaInfoAuthEntity(int userid, string country, string province,string city, int status);
        IpAreaInfoAuthEntity FindAreaInfoAuthEntity(int userid, string country, int status);
        bool AreaInfoAuthEntityExists(int userid, string country, string province, string city);
        DateTime? FindUserTokenLastAuthDateTime(int userid);
       // IEnumerable<IpAreaInfoAuthEntity> FindUserFirstAuthAreaInfoList(int userId, int top);
        IpAreaInfoAuthEntity FindUserLastTokenAuthIpAreaInfo(int userid, string country, string province, string city);

        /// <summary>
        /// 更新用户指定IP区域认证状态为“已认证”
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="country"></param>
        /// <param name="province"></param>
        /// <param name="city"></param>
        /// <returns></returns>
        int AuthIpAreaInfoSuccess(int userid, string country, string province, string city);
    }

    public interface IUserDeviceAuthRepository : IMySQLRepository<UserDeviceAuthEntity>
    {
        UserDeviceAuthEntity FindUserDevice(int userid,string deviceId,byte type=0);
        IEnumerable<UserDeviceAuthEntity> FindUserFirstAuthDeviceInfo(int userId, int authStatus);
        bool Exists(int userid,string deviceid,byte type=0);
        UserDeviceAuthEntity FindLastDeviceAuthInfo(int userId, string devicerId);

        /// <summary>
        /// 更新用户所有 设备/ClientId 认证状态为“已认证”
        /// </summary>
        /// <param name="userid"></param>
        /// <returns></returns>
        int AuthUserDeviceSuccess(int userid);
    }

    public interface IIpAreaTokenRepository : IMySQLRepository<IpAreaTokenEntity>
    {
        IpAreaTokenEntity FindLastTokenAuth(int userid, string country, string province, string city);
    }

    public interface IDeviceTokenAuthRepository : IMySQLRepository<DeviceTokenAuthEntity>
    {
        DeviceTokenAuthEntity FindLastDeviceTokenAuth(int userId, string devicerId, byte type = 0);
    }
}
